import { GSprite } from "../../../../../com/mui/controls/GSprite";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GTextFormat } from "../../../../common/GTextFormat";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { GBox } from "../../../../../com/mui/containers/GBox";
import { GBoxDirection } from "../../../../../com/mui/containers/globalVariable/GBoxDirection";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { Language } from "../../../../../extend/language/Language";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { DailySpecialInfo } from "../../../model/DailySpecialInfo";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { CutDataUtil } from "../../../../common/tools/CutDataUtil";
import { UICompomentPool } from "../../../../../com/mui/utils/UICompomentPool";
import { SpecialRewardGoodItem } from "./SpecialRewardGoodItem";
import { DailyRule } from "../../../rules/DailyRule";
import { _info } from "../../../../../this/_info";
import { _index } from "../../../../../this/_index";
type int = number;
//class OpenSeverRewardItem
    
    export  class OpenSeverRewardItem extends GSprite
    {
        constructor()
        {
            super();
            this.initUI();
            return;
        }

        /* internal  */onOptBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._info) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.DailySpecialGetRewardReq, {"info": _info, "index": _index}));
            }
            return;
        }

        protected initUI(): void
        {
            var loc1=null;
            this._condTxt = new Object /* flash.text.TextField */();
            loc1 = new GTextFormat("", 12, GlobalStyle.color1Uint);
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._condTxt.defaultTextFormat = loc1;
            this._condTxt.filters = [FilterConst.nameGlowFilter];
            this._condTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._condTxt.multiline = true;
            this._condTxt.wordWrap = true;
            this._condTxt.textColor = GlobalStyle.color1Uint;
            this._condTxt.mouseEnabled = false;
            this._condTxt.x = 0;
            this._condTxt.y = 20;
            this._condTxt.width = 145;
            addChild(this._condTxt);
            this._rewardBox = new GBox();
            this._rewardBox.direction = GBoxDirection.HORIZONTAL;
            this._rewardBox.y = 12;
            addChild(this._rewardBox);
            this._optBtn = new GButton();
            this._optBtn.styleName = "Button";
            this._optBtn.label = Language.getString(20935);
            this._optBtn.setSize(70, 22);
            this._optBtn.enabled = false;
            this._optBtn.x = 358;
            this._optBtn.y = 20;
            this._optBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOptBtnClickHandler);
            addChild(this._optBtn);
            this._optTxt = new Object /* flash.text.TextField */();
            this._optTxt.defaultTextFormat = loc1;
            this._optTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._optTxt.mouseEnabled = false;
            this._optTxt.multiline = true;
            this._optTxt.wordWrap = true;
            this._optTxt.filters = [FilterConst.nameGlowFilter];
            this._optTxt.width = 150;
            this._optTxt.y = 10;
            this._optTxt.x = 315;
            this._optTxt.textColor = GlobalStyle.color1Uint;
            this._line = GlobalClass.getBitmap(ImagesConst.SplitLine);
            this._line.width = this.width;
            this._line.y = this.height;
            addChild(this._line);
            return;
        }

        public updateData(arg1: DailySpecialInfo, arg2: int): void
        {
            var loc2=null;
            var loc3=0;
            var loc5=null;
            this.clear();
            this._info = arg1;
            this._index = arg2;
            this._condTxt.htmlText = HTMLUtil.addColor(CutDataUtil.getStringValueWithoutsharp(arg1.specialActiveInfo.condDesc)[arg2], GlobalStyle.color1);
            if (this._condTxt.numLines != 2) 
            {
                this._condTxt.y = 20;
            }
            else 
            {
                this._condTxt.y = 10;
            }
            var loc1=arg1.rewardDataList[arg2];
            var loc4=loc1.length;
            while (loc3 < loc4) 
            {
                loc2 = loc1[loc3];
                (loc5 = UICompomentPool.getUICompoment(SpecialRewardGoodItem) as SpecialRewardGoodItem).updateData(loc2);
                this._rewardBox.addChild(loc5);
                ++loc3;
            }
            this._rewardBox.x = 170 + (150 - this._rewardBox.numChildren * 40) / 2;
            this._rewardBox.invalidate();
            if (arg1.rewardGetRule != DailyRule.SpecialDailyRewardGetBtn) 
            {
                if (contains(this._optBtn)) 
                {
                    removeChild(this._optBtn);
                }
                if (!contains(this._optTxt)) 
                {
                    addChild(this._optTxt);
                }
                if (arg1.rewardGetRule != DailyRule.SpecialDailyRewardGetMail) 
                {
                    if (arg1.rewardGetRule != DailyRule.SpecialDailyRewardGetAtOnce) 
                    {
                        this._optTxt.htmlText = HTMLUtil.addColor(Language.getString(21048), GlobalStyle.color1);
                    }
                    else 
                    {
                        this._optTxt.htmlText = HTMLUtil.addColor(Language.getString(70920), GlobalStyle.color1);
                    }
                }
                else 
                {
                    this._optTxt.htmlText = HTMLUtil.addColor(Language.getString(21031), GlobalStyle.color1);
                }
            }
            else 
            {
                if (contains(this._optTxt)) 
                {
                    removeChild(this._optTxt);
                }
                if (!contains(this._optBtn)) 
                {
                    addChild(this._optBtn);
                }
            }
            return;
        }

        public onGetRewardRes(): void
        {
            var loc1=0;
            var loc3=null;
            var loc2=this._rewardBox.numChildren;
            while (loc1 < loc2) 
            {
                loc3 = this._rewardBox.getChildAt(loc1) as SpecialRewardGoodItem;
                loc3.flyToPack();
                ++loc1;
            }
            if (this._optBtn) 
            {
                this._optBtn.enabled = false;
            }
            return;
        }

        public updataGetRewardState(arg1: int): void
        {
            if (this._optBtn) 
            {
                var loc1=arg1;
                switch (loc1) 
                {
                    case 0:
                    {
                        this._optBtn.enabled = false;
                        this._optBtn.label = Language.getString(70903);
                        break;
                    }
                    case 1:
                    {
                        this._optBtn.enabled = true;
                        this._optBtn.label = Language.getString(70908);
                        break;
                    }
                    case 2:
                    {
                        this._optBtn.enabled = false;
                        this._optBtn.label = Language.getString(70918);
                        break;
                    }
                }
            }
            return;
        }

        protected clear(): void
        {
            var loc1=null;
            this._info = null;
            this._index = -1;
            this._optBtn.enabled = false;
            while (this._rewardBox.numChildren > 0) 
            {
                loc1 = this._rewardBox.removeChildAt(0) as SpecialRewardGoodItem;
                loc1.dispose();
                UICompomentPool.disposeUICompoment(loc1);
            }
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            this.clear();
            super.dispose(arg1);
            return;
        }

        public /* override */ get height(): number
        {
            return 55;
        }

        public /* override */ get width(): number
        {
            return 465;
        }

        /* internal */ /* var */_condTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_rewardBox: GBox;

        /* internal */ /* var */_optBtn: GButton;

        /* internal */ /* var */_optTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_info: DailySpecialInfo;

        /* internal */ /* var */_index: int;

        /* internal */ /* var */_line: Object /* flash.display.Bitmap */;
    }
